using UnityEngine;
using System.Collections;

public class PlayerController : MonoBehaviour {
	public GameObject Player;
	public Map MapRef;
	public int Movespeed = 10;
	private float[] moveCoords = new float [2];
	private bool boolMove = false;
	void Start () {
		
		LayerMask FloorMask = 31;
		//print(LayerMask.NameToLayer("Floor"));
	}
	void Update () {
		Ray cameraRay = Camera.main.ScreenPointToRay(Input.mousePosition);
		RaycastHit hit;
		LayerMask floorMask = 1 << 8;
		
		if(Physics.Raycast(cameraRay, out hit, 100, floorMask)){
			//Debug.DrawLine(ray.origin, hit.point);
			//Player.transform.position = hit.point;
			//MapRef.PathToCoor(x, y, 0, 0);
			//print(hit.point.ToString());
			float x = hit.point.x;
			float y = hit.point.z;
			Move(x,y);
		}
	}
	public void Move(float x, float z){
		//print("Mouse(" + x + "," + z + ")");
		//Player.transform.position = new Vector3(x, 0.58f, z);
		Vector3 test = new Vector3(x, 0.58f, z) - Player.transform.position;
		float multiplier = Mathf.Sqrt(Mathf.Pow(test.x, 2) + Mathf.Pow(test.y, 2))/Movespeed;
		print(multiplier);
		Player.transform.rigidbody.AddForce(test.x*multiplier, 0, test.z*multiplier, ForceMode.VelocityChange);
	}
}